package com.openlogic.logic.mapstruct;

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import org.dozer.Mapper;
import org.noear.solon.annotation.Component;

import com.openlogic.common.core.mapstruct.EntityMapper;
import com.openlogic.datasource.api.dto.DataSourceDto;
import com.openlogic.datasource.api.entity.DataSourceEntity;
import com.openlogic.datasource.api.vo.DataSourceVo;

/**
 * @ClassName: DataSourceMapperStruct
 * @Description: 数据源信息表 Mapper 实体映射
 * @author weiyongpeng
 * @date 2024年11月9日 上午9:50:57
 */
@Component
public class DataSourceMapperStruct implements EntityMapper<DataSourceDto, DataSourceEntity, DataSourceVo> {

	 /**
     * dozer转换的核心mapper对象
     */
    public static final Mapper converter = new org.dozer.DozerBeanMapper();

	@Override
	public DataSourceDto toDTO(DataSourceEntity e) {
		return converter.map(e, DataSourceDto.class);
	}

	@Override
	public List<DataSourceDto> toDTO(List<DataSourceEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataSourceDto.class))
		        .collect(Collectors.toList());
	}

	@Override
	public DataSourceVo toVO(DataSourceEntity e) {
		return converter.map(e, DataSourceVo.class);
	}

	@Override
	public List<DataSourceVo> toVO(List<DataSourceEntity> es) {
		return Optional.ofNullable(es)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataSourceVo.class))
		        .collect(Collectors.toList());
	}

	@Override
	public DataSourceEntity toEntity(DataSourceDto d) {
		return converter.map(d, DataSourceEntity.class);
	}

	@Override
	public List<DataSourceEntity> toEntity(List<DataSourceDto> ds) {
		return Optional.ofNullable(ds)
		        .orElse(Collections.emptyList())
		        .stream()
		        .map(bean -> converter.map(bean, DataSourceEntity.class))
		        .collect(Collectors.toList());
	}
}
